package com.ziroom.zifamily.zfms.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.TimeUnit;

/**
 * Hystrix配置参考: https://blog.csdn.net/shilu89757/article/details/79363295
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2018年11月24日 16:09
 * @since 1.0
 */
@RestController
@RequestMapping("monitor")
public class MonitorController {

    @Autowired
    private RestTemplate restTemplate;

    /** 运维v.ziroom.com监控使用 */
    @RequestMapping("v")
    public String monitor() {
        return "ok";
    }

    /** @HystrixCommand(fallbackMethod = "restFallback") */
    @RequestMapping("rest")
    public String rest() {
        try {
            TimeUnit.MILLISECONDS.sleep(1100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String str = restTemplate.getForObject("http://www.baidu.com", String.class);
        return str;
    }

    public String restFallback() {
        return "fallback";
    }
}
